<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/


class PhpFox_Mod_Video_ComponentUploadImage extends BaseComponent
{
    function process()
    {
    	$oReq = &App::getRequest();

    	$iUploadedId = (($iId = $oReq->get('imageid')) ? $iId : $this->getParam('iId'));

		if ( !$iUploadedId )
		{
			return App::_trigger_error('$iUploadedId is not set.', __FILE__, __LINE__);
		}
		
		if(!$aVideo = $this->oDatabase->getRows("SELECT * FROM
   			". App::getT('videos'.(App::getParam('vid_approve') ? "_pending" : '')) ." AS v
   			WHERE v.vid_userid = '". App::getUser('id') ."' AND v.vid_id='". $iUploadedId ."'"))
		{
			App::gotoUrl('public.account.submit');
		}
		
		if ( !empty($_FILES['image']['name']) )
		{
			$sDestPath = App::getParam('video.image.path') . (App::getParam('vid_approve') ? "pending_" : '');

 			App::loadClass('file/Image');
			$oImage = &new file_Image();

			if ($oImage->upload('image', $sDestPath, $iUploadedId, 'jpg'))
            {
            	$oImage->loadInfo($sDestPath.$iUploadedId.'.jpg');
				$oImage->_checkLimits();
			}

			$this->addErrors($oImage->getErrors());

			if (!count($this->getErrors()))
	        {
				$oImage->makeThumbnail($sDestPath.$iUploadedId.'.jpg', App::getSetting('upload_set_size_thumb'), App::getSetting('upload_set_size_thumb'));
			}

			App::gotoUrl('public.account.submit.add-video', array('mode' => $oReq->get('mode'), 'uploaded' => $iUploadedId));
		}

		$this->oTpl->assign('iId', $iUploadedId);
		$this->oTpl->assign('sMode', $oReq->get('mode'));

		return $this->oTpl->fetch('UploadImage.html');
    }
}

?>